Add Thumbnail In WordPress

How To Add Featured Image or Add Thumbnail In WordPress Theme?

While writing a blog post, you may in need to add thumbnail in WordPress. Most of the people know it with the name “featured image”.

It is one of the most important parts of a WordPress post. Most of the WordPress themes support the feature to add the featured image.

But what would you do when your theme won’t have the featured image theme support option? In such situation, you have to add thumbnail in WordPress theme manually.

If you are developing a WordPress theme then you must know the proper way to add the thumbnail theme support.

Let Me Tell You How Can You Add Thumbnail In WordPress?

First of all, you should know the proper way to add the theme support option for the thumbnails. If you know the WordPress theme file structure then it won’t be any problem.

All the functions of the WordPress theme are declared in one of the most important files of the theme. the function.php file is responsible for loading all the functions.

1:- To show an option to add featured image in the WordPress post editor, you have to add one line of code in the functions.php file to allow the theme support.

add_theme_support(‘post-thumbnails’);

It will show an option in the WordPress post editor to add the featured image. But it won’t display until you add another code in the file wherever you want to show the thumbnail.

2:- If you want to show the featured image with the posts on the blog’s page or any other page then you have to add the PHP code. You have to add the thumbnail code in the PHP loop.

<?php the_post_thumbnail(); ?>

This will pick up the thumbnail.

If you want to add any image size to use with the the_post_thumbnail() function then it can be done.

Just add the code shown below.

add_image_size(‘banner-image’, 920, 400);

Here the “banner-image” can be used to pick the size of the image mentioned here. The image with the width=900px and the height=400px is chosen.

You can change the size of the image according to the layout of your website. If you want to add thumbnail in WordPress post then you can use the small size of the image.

3:- To pick the image with the added dimensions, you have to use the code to display it.

<?php the_post_thumbnail(‘banner-image’); ?>

Similarly, you can use the featured image for your posts, pages, or any other page. When you create the home page of your website then you would need to use the different size of featured images.

4:- Let me give show you the default loop which is used to check whether the post thumbnail is present.

if ( has_thumbnail() ) {

the_post_thumbnail();

}

5:- If you want to set the size of the featured images for your posts then you can do that with another WordPress function.

set_post_thumbnail_size( 100, 100 );

There are many experiments which can be done with the featured images. You can add featured image size using a specific image and with the use of the WordPress function to pick up that image size as shown above.

Can You Now Add Thumbnail In WordPress Theme?

The design of the WordPress website influence your readers and you can add a plus point by showing the featured images with the posts.

When you add excerpt in WordPress theme then along with that, you should maintain the appearance using the thumbnails. There are many options for adding the different size of featured images.

You can use any. Though I have explained the proper way to add thumbnail in WordPress but still, if you face any problem then feel free to ask.

by Ravi Chahar

A WordPress Professional and the LinkedIn Influencer. A coder by passion and a blogger by choice. WordPress theme development is his forte. He is your WordPress guy who will teach you how to solve WordPress errors, WordPress security issues, design issues and what not.


Get Free Updates Into Your Inbox

Learn Everything Just Like I Did

SUBSCRIBE



5 comments

  1. Hi Ravi,

    Happy Friday! I am loving all the coding posts your are publishing. Thankfully, I’m saving them all in Bloglovin. ? This is an extremely helpful post for me. I appreciate you taking the time to share it with us!

    B

    1. Hey Bren,

      It’s good to know that this post can help you. When you develop or design any theme, you would in need to add this feature. People like to show the featured image along with their posts.

      Thanks for your support.

      ~Ravi

  2. Hi Ravi,

    Excellent. I’m big on Thumbnails because readers dig previews before clicking through. Like leaving a trail of breadcrumbs for attracting a mouse, or maybe, bits of cheese ? Readers love images. Eye candy. Use thumbnails to say 1,000 words without putting strains on your site because before you crunch or thumb images, even if you use a CDN the storage adds up and your blog slows down. Minimalism rocks in the blogging game.

    Thanks for the tutorial Ravi ?

    Ryan

    1. Hey Ryan,

      Sure, it is like showing a piece of cheese. We all know that the visual content influence the visitors and it’s important to show the thumbnail of your blog post on the blog page.

      It can be done using the code mentioned above. You may have noticed a few themes which don’t support the thumbnails. To get rid of it, you can add your own theme support option.

      Thanks for stopping by.

      Have a rocking day.

      ~Ravi

    2. Hey Ryan,

      Sure, it is like showing a piece of cheese. We all know that the visual content influence the visitors and it’s important to show the thumbnail of your blog post on the blog page.

      It can be done using the code mentioned above. You may have noticed a few themes which don’t support the thumbnails. To get rid of it, you can add your own theme support option.

      Thanks for stopping by.

      Have a rocking day.

      ~Ravi

Leave a Reply

Your email address will not be published. Required fields are marked *